<!--box slide right-->
<div class="box_slide left clearfix">
    <div class="head_box_slide">
        <span class="block span_title_slide icon_chat_32">SHOWBOX</span>
        <span class="block chat_loading"></span>
    </div>
    <div class="content_box_slide chatbox_ajax">
        <!-- contnet-->
         
        <!-- contnet-->
          <?php $this->load->controller('chatbox/ndchatbox');?>
        <!-- end content-->
        
        <!-- end content-->        
    </div>
    <div class="inputchat clearfix">
            <input class="nd"  type="text" name="ndchat"/>
            <input class="gui" type="submit" value="Send" />
        </div>
    <div class="bottom_box_slide"></div>
</div>
<!--end box slide right-->	

<script>
function ok (data, status){
        //$(data).toggleClass('unpub');
}
    
function loiaj(xhr, reason, ex){
    alert('loi');
    $("div .box_ajax").html('loi');
}
function test (data, status){
        alert(data);
}
function ndchat(data, status){
     $('.chatbox_ajax').load('<?php echo base_url();?>chatbox/ndchatbox'); 
}

$(document).ready(function(){
    point = 1;
    $('.gui').live('click',function(){
        if(point<0){
            alert('Point <=0');
            return;
        }
        var dt = $('.inputchat .nd').val(); 
        $('.inputchat .nd').val("");
        $.ajax({
            type:"POST",
            url:'<?php echo base_url();?>chatbox/adddata',
            data:{data:dt},
            success:ndchat,
            error:loiaj        
        });
        return false;
    });
      $(document).live('keypress', function(e){
          if(e.which === 13) { // return
          if(point<0){
                alert('Point <=10');
                return;
            }
              var dt = $('.inputchat .nd').val(); 
                $('.inputchat .nd').val("");
                $.ajax({
                    type:"POST",
                    url:'<?php echo base_url();?>chatbox/adddata',
                    data:{data:dt},
                    success:ndchat,
                    error:loiaj        
                });
          }});
    
    setInterval(function() {
        $('.chat_loading').html('<img src="<?= base_url()?>temp/images/load.gif"/>');
        $('.chatbox_ajax').load('<?php echo base_url();?>chatbox/ndchatbox');       
        $('.chat_loading img').fadeOut(1000);
      // Do something every 5 seconds
    }, 5000);
})

</script>
<style>
.chat_loading{position:absolute;width:24px;height:24px;right:36px;top:20px;}
.chatbox_ajax ul{list-style: none;}
.inputchat{margin:10px 10px 10px 10px;background:#064d7e;padding:10px;}
.nd{height:35px;width:164px;}
</style>